package com.tring.ysyn.util;

import lombok.Data;
import lombok.EqualsAndHashCode;


/**
 * @Date: 2022/3/8
 * @ClassName: Result
 * @Description: 返回类
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Result<T> {

    //  未登录
    public static final int NO_LOGIN = 401;
    // 成功
    public static final int SUCCESS = 200;
    // 失败
    public static final int FAIL = 500;
    // 没有权限
    public static final int NO_PERMISSION = 403;

    private String msg;

    private int code;

    private T data;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<T>(SUCCESS, "success");
    }

    public static <T> Result<T> success(String msg) {
        return new Result<T>(SUCCESS, msg);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(SUCCESS, "success", data);
    }

    public static <T> Result<T> failed(int code, String msg) {
        return new Result<T>(code, msg);
    }

    public static <T> Result<T> failed(String msg) {
        return new Result<T>(FAIL, msg);
    }
}
